<template>
    <div class="search-history">
        <van-cell-group>
            <van-cell title="搜索历史">
               <div v-if="isDeletShow">
                <span @click="$emit('clear-search-histories')">全部删除</span>
                &nbsp; &nbsp;
                <span @click="isDeletShow=false">完成</span>
               </div>
                <van-icon name="delete" v-else @click="isDeletShow=true"/>
            </van-cell>
            <van-cell v-for="(item,index) in searchHistories" :key="index" :title="item" @click="onSearchItemClick(item,index)">
                <van-icon name="close" v-show="isDeletShow" />
            </van-cell>
           
        </van-cell-group>
    </div>
</template>

<script>
export default {
    name: 'searchHistory',
    props:{
        searchHistories:{
            type:Array,
            required:true
        }
    },
    data(){
        return{
            isDeletShow:false //控制删除显示状态
        }
    },
    methods:{
        onSearchItemClick(item,index){
            if(this.isDeletShow){
                this.searchHistories.splice(index,1)
            }else{
                this.$emit('search',item)
            }
        }
    }
}
</script>

<style lang="less" scoped>

</style>